<!--
 * @Description: 	项目管理策划明细表
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2022-02-15 14:37:10
 * @LastEditTime: 2023-01-13 17:55:44
 * @FilePath: \cscec-pms-admin\src\views\project\projectManagementPlanning\projectManagementPlanningSchedule\index.vue
-->
<template>
  <base-breadcrumb>
    <!-- 搜索 -->
    <searchData ref="search" :search-data="searchOption" @search="search" @reset="reset" />
    <!-- 搜索 -->
    <a-card>
      <!-- <title-name title="项目管理策划明细表" /> -->
      <list-table ref="table" row-key="id" :columns="columns" :request="loadData" :alert="true" show-size-changer show-quick-jumper>
        <template slot="version" slot-scope="text, record">
          <span v-if="text < 1">--</span>
          <a v-else @click="handleVersionRecord(record)">
            V
            {{ text }}
          </a>
        </template>
        <template slot="operation" slot-scope="text, record">
          <MoreButton>
            <a v-if="record.status === 0 && hideBuquBtn()" @click="handleSign(record)">签收</a>
            <a v-if="record.status !== 0" @click="handleOperation('detail', record)">查看</a>
            <a v-if="(record.status === 1 || record.status === 4) && hideBuquBtn()" @click="handleOperation('update', record)">编辑</a>
            <!-- <a @click="handleOperation('update', record)">编辑</a> -->
            <a v-if="record.status === 3 && hideBuquBtn()" @click="handleOperation('change', record)">变更</a>
            <a v-if="record.status !== 0 && record.status !== 1" @click="$bus.$emit('showApprovalDetailsDialog', record.id)">审批信息</a>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
    <!-- 版本记录 -->
    <VersionRecord :visible.sync="versionVisible" :data="versionData" />
    <!-- 版本记录 -->
  </base-breadcrumb>
</template>
<script>
import { searchOption, columns } from './model.js'
import MoreButton from '@/components/MoreButton'
import { list } from '@/api/projectManagementPlanning/projectManagementPlanningSchedule'
import Vue from 'vue'
import { pageName } from '../projectManagementPlanningComponents/components/model.js'
import VersionRecord from './components/VersionRecord'
import { async } from 'regenerator-runtime'
export default {
  name: 'projectManagementPlanningSchedule' + Date.now(),
  components: {
    MoreButton,
    VersionRecord
  },
  data() {
    return {
      // 搜索选项
      searchOption,
      // 表头
      columns,
      // 查询参数
      searchData: {},
      // 项目信息
      projectInfo: {},
      // 版本记录显示隐藏
      versionVisible: false,
      // 版本记录信息
      versionData: {},
      loadData: async (parameter) => {
        if (Object.keys(this.projectInfo || {}).length === 0) {
          await this.getProjectName()
        }
        let { pageNo: pageNum, pageSize } = parameter
        let { status } = this.searchData
        let { projectId } = this.projectInfo
        // console.log(9999999, pageNum, pageSize, param)
        return list
          .getPagePlanTaskDetail({
            pageNum,
            pageSize,
            param: {
              projectId,
              status
            }
          })
          .then((res) => {
            return res
          })
      }
    }
  },
  methods: {
    /**
     * @description: 搜索
     * @param {Object} value 搜索数据
     * @return {Void}
     */
    search(value) {
      this.searchData = value || {}
      this.$refs.table.refresh()
    },
    /**
     * @description: 表格数据加载方法
     * @param {Object} parameter 分页信息
     * @return {Promise} 接口Promise
     */
    // async loadData(parameter) {
    //   try {
    //     if (Object.keys(this.projectInfo).length === 0) {
    //       await this.getProjectName()
    //     }
    //     const { pageNo: pageNum, pageSize } = parameter
    //     const { status } = this.searchData
    //     const { projectId } = this.projectInfo
    //     const res = await list.getPagePlanTaskDetail({
    //       pageNum,
    //       pageSize,
    //       param: {
    //         projectId,
    //         status
    //       }
    //     })
    //     if (res.code === 200) {
    //       return Promise.resolve(res)
    //     } else {
    //       return Promise.reject()
    //     }
    //   } catch (error) {
    //     console.log(error)
    //     return Promise.reject()
    //   }
    // },
    /**
     * @description: 获取当前登录人项目名称
     * @param {void}
     * @return {void}
     */
    getProjectName() {
      return new Promise((resolve, reject) => {
        const {
          currentPost: { id }
        } = Vue.getAcloudProvider().getUserInfo()
        list.downProject({ deptOrgIds: [id], projectStatus: '1,2,3,4,5,6' }).then(({ data }) => {
          this.projectInfo = data[0] || {}
          this.reset()
          resolve()
        })
      })
    },
    /**
     * @description: 搜索重置
     * @param {void}
     * @return {void}
     */
    reset() {
      this.$refs.search.form.setFieldsValue({ projectName: this.projectInfo?.projectName })
    },
    /**
     * @description: 操作
     * @param {string} pageType 操作类型
     * @param {object} record 行数据
     * @return {void}
     */
    handleOperation(pageType, record) {
      const { id, code } = record
      this.$router.push({
        path: '/project/projectManagementPlanning/projectManagementPlanningComponents',
        query: {
          id,
          pageType,
          editModel: pageType == 'detail' ? 0 : 1,
          pageName: pageName[code - 1]
        }
      })
    },
    approvalDetail() {
      this.$router.push({
        path: '/project/approvalDetail'
      })
    },
    /**
     * @description: 签收
     * @param {object} record 行数据
     * @return {void}
     */
    handleSign(record) {
      const { id } = record
      const vm = this
      this.$confirm({
        title: '温馨提示',
        content: '请确认是否要签收？',
        onOk() {
          list
            .signIn({
              id,
              statusEnum: 1
            })
            .finally(() => {
              vm.$refs.table.refresh(false)
            })
        }
      })
    },
    /**
     * @description: 版本记录
     * @param {object} record 行数据
     * @return {void}
     */
    handleVersionRecord(record) {
      this.versionVisible = true
      this.versionData = record
    }
  }
}
</script>
<style lang="less" scoped>
</style>
